// px转cm公共方法
function prasePxToCm(px)
{
	var targetEleWidth=1,cm;
	var createEle=document.createElement('input');
	var body = document.getElementsByTagName("body");
	createEle.setAttribute("style","width:1cm !important;height:1cm !important;border-width:0px !important;padding:0px !important;margin:0px !important;");
	createEle.id="elementId_"+new Date().getTime();
	createEle.type="hidden";
	body[0].appendChild(createEle);
	var targetEle=document.getElementById(createEle.id);
	targetEleWidth=window.getComputedStyle(targetEle).width.match(/^\d+\.?\d*/)[0];
	cm=px/targetEleWidth;
	targetEle.parentNode.removeChild(targetEle);
	return cm.toFixed(1); 
}


//获取DPI
// function js_getDPI(width,height) {
function js_getDPI() {
    const div = document.createElement('div')
    // div.style.cssText = 'height: '+width+'px; width: '+height+'px;'
    div.style.cssText = 'height: 1in; left: -100%; position: absolute; top: -100%; width: 1in;'
    document.body.appendChild(div)
    const devicePixelRatio = window.devicePixelRatio || 1,
    dpi = div.offsetWidth * devicePixelRatio;
    return dpi
	// var arrDPI = new Array()
	// var tmpNode = document.createElement( "DIV" );
	// tmpNode.style.cssText = 'width:'+width+';height:'+height+';position:absolute;left:0px;top:0px;z-index:99;visibility:hidden';
	// document.body.appendChild( tmpNode );
	// console.log('tmpNode='+tmpNode.offsetWidth);
	// console.log('tmpNode='+tmpNode.offsetHeight);
	// arrDPI[0] = parseInt( tmpNode.offsetWidth );
	// arrDPI[1] = parseInt( tmpNode.offsetHeight );
	// return arrDPI
}
export default {
    prasePxToCm,
	js_getDPI
}